{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "from keras.preprocessing.image import ImageDataGenerator\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "import copy\n",
    "\n",
    "def make_test_generator():\n",
    "    test_data_root = 'D:/Data/test'  # 测试集存放路径\n",
    "\n",
    "    data_gen_args = dict()\n",
    "    test_image_datagen = ImageDataGenerator(**data_gen_args)\n",
    "    test_image_generator = test_image_datagen.flow_from_directory(\n",
    "        test_data_root,\n",
    "        target_size=(288,288),\n",
    "        class_mode=None,\n",
    "        batch_size=3,\n",
    "        color_mode='rgb',\n",
    "        shuffle=False)\n",
    "\n",
    "    print(len(test_image_generator.filenames))\n",
    "    bidx = 1\n",
    "    for raw_images in test_image_generator:\n",
    "        if bidx > np.ceil(16/test_image_generator.batch_size):\n",
    "            break\n",
    "            \n",
    "        idx = (bidx-1) * test_image_generator.batch_size\n",
    "        filenames = test_image_generator.filenames[idx : idx + test_image_generator.batch_size]\n",
    "        \n",
    "        bidx += 1\n",
    "        yield filenames,raw_images"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Found 16 images belonging to 1 classes.\n",
      "16\n",
      "['0\\\\000000000005.jpg', '0\\\\000000000008.jpg', '0\\\\000000000009.jpg']\n",
      "['0\\\\000000000019.jpg', '0\\\\000000000021.jpg', '0\\\\000000000023.jpg']\n",
      "['0\\\\000000000032.jpg', '0\\\\000000000036.jpg', '0\\\\000000000039.jpg']\n",
      "['0\\\\000000000041.jpg', '0\\\\000000000045.jpg', '0\\\\000000000048.jpg']\n",
      "['0\\\\000000000050.jpg', '0\\\\000000000057.jpg', '0\\\\000000000062.jpg']\n",
      "['0\\\\000000000066.jpg']\n"
     ]
    }
   ],
   "source": [
    "for filenames,images in make_test_generator():\n",
    "    print(filenames)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
